<!DOCTYPE html>
<html lang="zh-CN>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>切换</title>
    <style>
        .box{
            width: 100px;
            height: 100px;
            background-color: aquamarine;
        }
        .hide{
            display: none;
        }
    </style>
</head>
<body>
    <button class="btn">切换</button>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <script>
        let btn=document.querySelector(".btn");
        // let box=document.querySelector(".box");
        let box=document.querySelectorAll(".box");
        btn.onclick=function(){
            // box.classList.toggle("hide");
            // for (let i = 0; i < box.length; i++) {
            //     box[i].classList.toggle("hide");
            // }
            box.forEach(obj=>{obj.classList.toggle("hide")});
        }
    </script>
</body>
</html>